//
//  SqlitManager.m
//  FMDB
//
//  Created by 袁飞 on 2017/3/13.
//  Copyright © 2017年 Yuanfei. All rights reserved.
//

#import "SqlitManager.h"

@implementation SqlitManager

+ (instancetype)sharedManager {
    
    static SqlitManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSString *dbPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:@"temp.db"];
        NSLog(@"%@", dbPath);
        
        manager = [SqlitManager databaseQueueWithPath:dbPath];
        [manager creatTable];
    });
    
    return manager;
}


- (void)creatTable {
    
    NSString *sql = @"creat table if not exists t_person(id integer not null primary key, name text, age integer);";
    
    [self inDatabase:^(FMDatabase *db) {
        
        BOOL isOK = [db executeUpdate:sql];
        if (isOK) {
            NSLog(@"创表成功");
        } else {
            NSLog(@"创表失败");
        }
    }];
}

@end
